<?php

  class XiajiAction extends CommonAction{
  
    public function index(){
	
	  $sons=$this->sons(session('uid'));
	  
	  $this->num=count($sons);
	  
	  
	  
	  $where['id']=array('IN',$sons);
	  
	  $this->mysons=M('users')->where($where)->order('id desc')->limit(10)->select();
	  
	  $this->display();
	
	}
  
  
    public function xiala(){
	
	  $sons=$this->sons(session('uid'));
	
	  $start=$_POST['num'];
	  
	  $mysons=M('users')->where($where)->order('id desc')->limit("$start,10")->select();
	
	  foreach($mysons as $v){
	  
	    $arr[]='<div class="dsmx">
<div class="left">
<img src="/Public/new/img/h-touxiang.png"/>
</div>
<div class="center">
<p class="p1">'.$v['nicheng'].'<img src="'.$v['touxiang'].'"/></p>
</div>
</div>';
	  
	  }
	
	  $ajax['data']=$arr;
	
	  $ajax['num']=$start+10;
	
	  $this->ajaxReturn($ajax);
	
	}
  
  
    public function sons(){
	
	  $re=M('users')->where('upline_id')->select();
	
	  if($re!=null){
	  
	    $one=array();
	  
	    foreach($re as $v){
		
		  $one[]=$v['id'];
		
		}
	  
	    
		$where['upline_id']=array('IN',$one);
	  
	    $two=M('users')->where($where)->select();
		
		$twoids=array();
		
		foreach($two as $v){
		
		  $twoids[]=$v['id'];
		  
		  $one[]=$v['id'];
		
		}
		
		$where['upline_id']=array('IN',$two);
		
		$three=M('users')->where()->select();
	    
		if($three!=null){
		
		  foreach($three as $v){
		  
		  
		    $one[]=$v['id'];
		  
		  }
		  
		
		}
		
	  
	  }
	
	  return $one;
	  
	}
  
  
  }